const { defineConfig } = require('@vue/cli-service')
const webpack = require('webpack')
const CompressionPlugin = require('compression-webpack-plugin')
const path = require('path')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false, //关闭语法检查
})

// const path = require("path");
const isDevelopment = process.env.NODE_ENV === 'development' // 判断是否是生产环境
const { name } = require('./package.json')
module.exports = {
  outputDir: './base-dist',
  // publicPath: isDevelopment ? './' :'./',
  // publicPath: './',
  productionSourceMap: false,
  lintOnSave: false, //关闭语法检查
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      patterns: [
        // 自己对应文件路径，全局变量路径，不能使用路径别名
        path.resolve(__dirname, './src/assets/style/main.less'),
      ],
    },
  },
  devServer: {
    proxy: {
      '/api': {
        target: 'http://testcr.ouyeelf.com/',
        // target: 'http://10.48.76.1:8080/',
        changeOrigin: true,
        pathRewrite: {
          '^/api': '',
        },
      },
    },
    client: {
      overlay: false,
    },
  },
  configureWebpack: {
    plugins: [
      // new CompressionPlugin(),
      new webpack.optimize.MinChunkSizePlugin({
        minChunkSize: 10000,
      }),
      new webpack.ProvidePlugin({
        process: require.resolve('process/browser'),
      }),
    ],
    optimization: {
      splitChunks: {
        automaticNameDelimiter: '-',
      },
    },
    resolve: {
      fallback: {
        process: require.resolve('process/browser'),
      },
      extensions: ['.js', '.vue', '.json'],
      alias: {
        '@': resolve('src'), // 本项目
      },
    },
  },
  chainWebpack: (config) => {
    config.module
      .rule('worker-loader')
      .test(/\.worker\.js$/)
      .use({
        loader: 'worker-loader',
        options: {
          inline: true,
        },
      })
      .loader('worker-loader')
      .end()
    config.plugins.delete('preload')
    config.plugins.delete('prefetch')
    config.plugin('define').tap((args) => {
      args[0]['process.env']['VUE_APP_DateTime'] = '"' + new Date() + '"'
      return args
    })
  },
  // build: {
  //   assetsPublicPath: './'
  // }
}
